module.exports = (app)=> {
  const DataTypes = app.Sequelize;
  const Devicetype = app.model.define('t_devicetype', {
    dt_index: {
      autoIncrement: true,
      type: DataTypes.INTEGER,
      allowNull: false,
      primaryKey: true
    },
    dt_typeid: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0
    },
    dt_typename: {
      type: DataTypes.STRING(64),
      allowNull: false,
      defaultValue: ""
    },
    dt_issupportext: {
      type: DataTypes.TINYINT,
      allowNull: false,
      defaultValue: 0
    },
    dt_isenable: {
      type: DataTypes.TINYINT,
      allowNull: false,
      defaultValue: 0
    },
    dt_rtdata_table: {
      type: DataTypes.STRING(64),
      allowNull: false,
      defaultValue: ""
    },
    dt_hisdata_table: {
      type: DataTypes.STRING(64),
      allowNull: false,
      defaultValue: ""
    },
    dt_typememo: {
      type: DataTypes.STRING(255),
      allowNull: true
    },
    dt_page: {
      type: DataTypes.STRING(255),
      allowNull: false,
      defaultValue: ""
    },
    dt_pre: {
      type: DataTypes.STRING(255),
      allowNull: false,
      defaultValue: ""
    },
    dt_icon: {
      type: DataTypes.STRING(255),
      allowNull: true,
      defaultValue: ""
    },
    haschildType: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 0
    },
    dt_MoniType: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0
    },
    dt_URL: {
      type: DataTypes.STRING(255),
      allowNull: true
    }
  }, {
    tableName: 't_devicetype',
    timestamps: false,
    underscored: false,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "dt_index" },
        ]
      },
    ]
  });

  Devicetype.associate = function() {
    app.model.TDevicetype.hasMany(app.model.TSubdevicetype, { as: 'subtype', sourceKey: 'dt_typeid', foreignKey: 'ts_Maintypeid' });
  };

 return Devicetype

};
